<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .short_table_list_cur table th{
        background-color: #fafafa
    }
</style>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span id="flowsetname"></span><div class="move_title"></div><?php include "../public/subturn.php";?></div></div>
    <div class="main-container">


        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=payment_xiangfu','80%','80%')">
                            <div class="choose_div" id="enginid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=payment_xiangfu','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">委托方</label>
                        <div class="layui-input-block">
                            <input type="text" id="lian_unit" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目资金情况</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">施工合同金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="shimoney" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计收款金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="incomeenginfee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计付款(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="payenginfee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计扣款(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="neikoufee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">累计项目费用报销(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="paybaofee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计结算支付(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="payment_xiangfu" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目余额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="balance" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">累计待扣(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="leikoudai" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目可用余额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="shengjiefee" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开票金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="piao_kai_money" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">进项票金额(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="piao_shou_money" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">进项票提供比率(%)</label>
                        <div class="layui-input-block">
                            <input type="text" id="jingongbi" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">项目所属单位</label>
                        <div class="layui-input-block">
                            <input type="text" id="engin_chanid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目应扣费用情况</span></div>
                </div>
            </div>
            <div class="layui-form-item" style="padding: 0 25px">
                <div class="short_table_list_cur">
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th colspan="4" style="text-align: center">管理费(元)</th>
                            <th colspan="4" style="text-align: center">成本票差额费(元)</th>
                            <th colspan="3" style="text-align: center">税费(元)</th>
                            <th colspan="3" style="text-align: center">税费利息(元)</th>
                            <th rowspan="2">应扣合计(元)</th>
                            <th rowspan="2">已扣合计(元)</th>
                            <th rowspan="2">待扣合计(元)</th>
                        </tr>
                        <tr>
                            <th>比例%</th>
                            <th>应扣</th>
                            <th>已扣</th>
                            <th>待扣</th>


                            <th>比例%</th>
                            <th>应扣</th>
                            <th>已扣</th>
                            <th>待扣</th>

                            <th>应扣</th>
                            <th>已扣</th>
                            <th>待扣</th>

                            <th>应扣</th>
                            <th>已扣</th>
                            <th>待扣</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="koukuaninfo">
                        </tbody>
                    </table>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>项目资料情况</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>中标通知书</label>
                        <div class="layui-input-block" id="liao_shuDiv">
                            <div class="radio-block" id="statusDiv">
                                <input type="radio" name="liao_shu" value="是" title="是">
                                <input type="radio" name="liao_shu" value="否" title="否" checked>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">说明</label>
                        <div class="layui-input-block">
                            <input type="text" id="liao_shu_shuo" name="liao_shu_shuo" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>施工合同</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="liao_shiDiv">
                                <input type="radio" name="liao_shi" value="是" title="是">
                                <input type="radio" name="liao_shi" value="否" title="否" checked>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">说明</label>
                        <div class="layui-input-block">
                            <input type="text" id="liao_shi_shuo" name="liao_shi_shuo" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>竣工验收资料</label>
                        <div class="layui-input-block">
                            <div class="radio-block" id="liao_yanDiv">
                                <input type="radio" name="liao_yan" value="是" title="是">
                                <input type="radio" name="liao_yan" value="否" title="否" checked>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">说明</label>
                        <div class="layui-input-block">
                            <input type="text" id="liao_yan_shuo" name="liao_yan_shuo" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>本次结算支付信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">结算编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" placeholder="请输入" disabled autocomplete="off" class="layui-input disabled">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>款项摘要</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhai" id="zhai" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>结算类型</label>
                        <div class="layui-input-block">
                            <select id="jietype" name="jietype" lay-filter="jietype" >
                                <option value="">请选择</option>
                                <option value="进度结算">进度结算</option>
                                <option value="最终结算">最终结算</option>
                            </select>
                            <p class="error" id="jietype_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>结算日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="jiedt" id="jiedt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">本次实际结算支付(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" readonly placeholder="" autocomplete="off" class="layui-input moneyinput disabled">
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联单据</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>
        </div>


        <div class="block-generic">
            <div class="layui-form-item height_auto">
                <div class="short_table_list" key="1">
                    <div class="opt-btn-group">
                        <div><span>支付渠道</span></div>
                        <div>
                            <button type="button" onclick="choose_dealcom()" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn">选择付款对象</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_row">删除行</button>
                            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary mingxibtn short_table_del_all">删除全部</button>
                        </div>
                    </div>
                    <table class="layui-table" lay-size="sm">
                        <thead>
                        <tr>
                            <th width="45">序号</th>
                            <th><text>*</text>付款对象</th>
                            <th><text>*</text>支付金额(元)</th>
                            <th><text>*</text>支付方式</th>
                            <th>账户账号</th>
                            <th>开户行</th>
                            <th>款项说明</th>
                        </tr>
                        </thead>
                        <tbody class="short_table_tbody" id="list_list"></tbody>
                    </table>
                    <div class="listerror">提示：<span></span></div>
                </div>
            </div>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            zhai: {required: true},
            jiedt: {required: true},
            kouguan: {required: true},
            koujian: {required: true},
            koucha: {required: true},
            koushui: {required: true},

        },
        messages:{
            zhai: {required: "请输入"},
            jiedt: {required: "请选择"},
            kouguan: {required: "请输入"},
            koujian: {required: "请输入"},
            koucha: {required: "请输入"},
            koushui: {required: "请输入"},
        }
    });


    function choose_dealcom(){
        openPage('../public/choose_dealcom.php?page=payment_xiangfu&choose_type=checkbox','80%','80%');
    }


    var pub_incdaotype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_payment_xiangfu}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                $("#number").val(data.number);
                $("#jiedt").val(data.jiedt);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }


                var shanginfo = res.data.shanginfo;
                if(shanginfo){
                    $("#liao_shu_shuo").val(shanginfo.liao_shu_shuo);
                    $("#liao_shi_shuo").val(shanginfo.liao_shi_shuo);
                    $("#liao_yan_shuo").val(shanginfo.liao_yan_shuo);

                    var liao_shu_str = '';
                    if(shanginfo.liao_shu == '是'){
                        liao_shu_str += '<input type="radio" name="liao_shu" checked value="是" title="是">';
                        liao_shu_str += '<input type="radio" name="liao_shu" value="否" title="否">';
                    }else{
                        liao_shu_str += '<input type="radio" name="liao_shu" value="是" title="是">';
                        liao_shu_str += '<input type="radio" name="liao_shu" checked value="否" title="否">';
                    }
                    $('#liao_shuDiv').html(liao_shu_str);

                    var liao_shi_str = '';
                    if(shanginfo.liao_shi == '是'){
                        liao_shi_str += '<input type="radio" name="liao_shi" checked value="是" title="是">';
                        liao_shi_str += '<input type="radio" name="liao_shi" value="否" title="否">';
                    }else{
                        liao_shi_str += '<input type="radio" name="liao_shi" value="是" title="是">';
                        liao_shi_str += '<input type="radio" name="liao_shi" checked value="否" title="否">';
                    }
                    $('#liao_shiDiv').html(liao_shi_str);

                    var liao_yan_str = '';
                    if(shanginfo.liao_yan == '是'){
                        liao_yan_str += '<input type="radio" name="liao_yan" checked value="是" title="是">';
                        liao_yan_str += '<input type="radio" name="liao_yan" value="否" title="否">';
                    }else{
                        liao_yan_str += '<input type="radio" name="liao_yan" value="是" title="是">';
                        liao_yan_str += '<input type="radio" name="liao_yan" checked value="否" title="否">';
                    }
                    $('#liao_yanDiv').html(liao_yan_str);
                }



                var incdaotype = res.data.incdaotype
                pub_incdaotype = res.data.incdaotype


                short_table_opt_func('',1);




                public_upload_file_load('upload_files');
                render_date();
                render_from();
                initParseMoney();
            }
        });

        form.on('select(jietype)', function(data){
            if(data.value == ''){
                $('#jietype_error').show().text('请选择');
                $('#jietype_error').parent().find('input').addClass('select_error');
            }else{
                $('#jietype_error').hide();
                $('#jietype_error').parent().find('input').removeClass('select_error');
            }
        });


        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');
            data = parseMoney(data);

            data.field.enginid = get_choose_val('enginid');
            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();
                formValid('enginid');
                if(data.field.enginid == undefined || !data.field.enginid){
                    validRes = false;
                }
                if(data.field.jietype == ''){
                    $('#jietype_error').show().text('请选择');
                    $('#jietype_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#jietype_error').hide();
                    $('#jietype_error').parent().find('input').removeClass('select_error');
                }
                if(!validRes){return false;}


                var shengjiefee = parseFloat($("#shengjiefee").val()) || 0;
                if(parseFloat(data.field.money) > parseFloat(shengjiefee)){
                    facade.error('本次实际结算支付，不能大于项目可用余额。');
                    return false;
                }
            }




            var list = [''];
            try {
                $('#list_list tr').each(function (i) {
                    var gonger = $(this).find('.gonger').val();
                    var money = $(this).find('.money').val();
                    var incdaotype = $(this).find('.incdaotype').find('input').val();
                    var banknum = $(this).find('.banknum').val();
                    var bankname = $(this).find('.bankname').val();
                    var explain = $(this).find('.explain').val();



                    var index = i + 1;
                    if(data.field.isturn > 0){
                        if(money == ''){
                            throw new Error('第'+index+'行，请输入支付金额');
                        }
                        if(!incdaotype){
                            throw new Error('第'+index+'行，请选择支付方式');
                        }
                    }


                    list.push({
                        gonger:gonger,
                        money:money,
                        incdaotype:incdaotype,
                        banknum:banknum,
                        bankname:bankname,
                        explain:explain,
                    });
                });
            } catch(e) {
                $(".listerror").find('span').text(e.message);
                $(".listerror").show();
                return false;
            }
            $(".listerror").hide();
            data.field.list = list;


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_payment_xiangfu, ask_flowdata_edit_payment_xiangfu, $(this).attr('but'));

            return false;
        });

    });



    $('#list_list').on('input propertychange','.money',function () {
        jisuan_money_all();
    });
    function jisuan_money_all() {
        var allmoney = 0;
        $('#list_list tr').each(function (i) {
            var money = parseValidNum($(this).find('.money').val()) || 0;

            allmoney = parseFloat(allmoney) + parseFloat(money);
        });
        $("#money").val(parseFormatNum(allmoney,2));
    }


    function update_refresh_row_func() {
        render_date();
        render_from();
        jisuan_money_all();
        $.each($("#list_list").children('tr'),function (key,val) {
            $(this).children('td:first-child').html(key+1);
        });
        setTimeout(function () {
            $(".short_table_list table tbody tr").click(function () {
                $(".short_table_list table tbody tr").removeClass('line-row');
                $(".short_table_list table tbody tr").attr('sle','');
                $(this).addClass('line-row');
                $(this).attr('sle','sle');
            });
        },1000);
    }



</script>
</body>
</html>
